import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * 
 */

/**
 * @author TrinhNX
 * @start_date	: 2015/08/10
 * @end_date 	:
 */
public class SamsungTest3Update {
	public static final int NUM_TEST = 1;

	public static void main(String[] args) throws FileNotFoundException {
		System.setIn(new FileInputStream("data\\samsung3.txt"));
		Scanner scanner = new Scanner(System.in);
		final long start = System.currentTimeMillis();
		for (int index = 0; index < NUM_TEST; index++) {
			// Initialize the map
			// We will store degree as key, base as value
			Map<Integer, Integer> result = new HashMap<Integer, Integer>(8);
			// Get the input
			// [0] is base, [1] is degree
			// First row
			final int m = scanner.nextInt();
			final int[][] first = new int[m][2];
			for (int i = 0; i < m; i++) {
				first[i][0] = scanner.nextInt();
				first[i][1] = scanner.nextInt();
			}
			// Second row
			final int n = scanner.nextInt();
			final int[][] second = new int[n][2];
			for (int i = 0; i < n; i++) {
				second[i][0] = scanner.nextInt();
				second[i][1] = scanner.nextInt();
			}
			// Do multiply
			for (int i = 0; i < m; i++) {
				for (int j = 0; j < n; j++) {
					int degree = first[i][1] + second[j][1];
					int base = first[i][0] * second[j][0];
					// If there is available, do increase
					// Put again.
					if (result.containsKey(degree)) {
						base += result.get(degree);
					}
					result.put(degree, base);
				}
			}
			System.out.println(result);
		}
		System.out.println("End after : "
				+ (System.currentTimeMillis() - start));
		scanner.close();
	}

}
